<template>
	<view class="page">
		<view class="input-box">
			<input v-model="code" placeholder="请输入充电桩编码"/>
		</view>
		<view class="confirm" @click.stop="confirm">确定</view>
	</view>
</template>

<script>
	import * as homeApi from '@/api/home/index.js'
	export default{
		data(){
			return{
				code:''
			}
		},
		onShow() {
			// #ifdef APP-PLUS || APP-PLUS-NVUE
			plus.navigator.setStatusBarStyle('dark');
			// #endif
		},
		methods:{
			confirm(){
				if(!this.code){
					uni.showToast({
						title:'请输入充电桩编号',
						icon:'none'
					})
					return
				}
				uni.showLoading({
					title:'请稍后'
				})
				homeApi.getChargeScan(this.code).then((res)=>{
					uni.hideLoading()
					if(res.data.deviceType==0){
						uni.navigateTo({
							url:'/pages/charge/bikeCharge?id='+res.data.chargingId
						})
					}
					else{
						uni.navigateTo({
							url:'/pages/site/selectChargGun?id=' + res.data.chargingId
						})
					}
					
				}).catch((errMsg)=>{
					uni.hideLoading()
					uni.showToast({
						title:errMsg,
						icon:'none'
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height:100vh;
		padding-left:60rpx;
		padding-right:60rpx;
	}
	.input-box{
		background: #FFFFFF;
		box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.06);
		border-radius: 26px;
		height:52px;
		width:100%;
		overflow: hidden;
		input{
			flex:1;
			width: 100%;
			height:52px;
			text-align: center;
			font-size:36rpx;
			font-weight: bold;
		}
	}
	
	.confirm{
		font-weight: bold;
		color: #FFFFFF;
		line-height: 27px;
		height: 51px;
		line-height:51px;
		font-size: 18px;
		width:100%;
		background-color:#6ABF6C;
		box-shadow: 0px 1px 2px 0px rgba(8, 139, 120, 0.3);
		border-radius: 60px;
		text-align: center;
		margin-top:30rpx;
		font-size: 36rpx;
	}
</style>
